#include "stdafx.h"

struct SAnimVertex 
{
	float x,y,z;
	float u,v;
	const static DWORD FVF = D3DFVF_XYZ | D3DFVF_TEX1;
};

void CTextureAnim::Init(LPDIRECT3DDEVICE9 _Device)
{
	SAnimVertex Vertexs[] = 
	{
		{-1,-1,0,0,1},
		{-1,1,0,0,0},
		{1,-1,0,1,1},
		{1,1,0,0,1}
	};
	_Device->CreateVertexBuffer(sizeof(Vertexs),0,SAnimVertex::FVF,D3DPOOL_MANAGED,&m_pVB,NULL);

	LPVOID pVertex;
	m_pVB->Lock(0,0,&pVertex,0);
	memcpy(pVertex,Vertexs,sizeof(Vertexs));
	m_pVB->Unlock();

	for (DWORD index = 0;index < ARRAY_COUNT(m_Textures);++index)
	{
		TCHAR StrName[128];
		ZeroMemory(StrName,sizeof(StrName));
		swprintf(StrName,TEXT("explode%d.dds"),index);
		D3DXCreateTextureFromFile(_Device,StrName,&m_Textures[index]);
	}
}

void CTextureAnim::Render(CEasyRender* _Render,float _Time)
{
	static float TmpTime;
	TmpTime += _Time;
	static int CurIndex;
	while (TmpTime > 0.1f)
	{
		TmpTime -= 0.1f;
		CurIndex++;
		if (CurIndex > ARRAY_COUNT(m_Textures) - 1)
		{
			CurIndex = 0;
		}
	}
	_Render->GetDevice()->SetTexture(0,m_Textures[CurIndex]);
	_Render->GetDevice()->SetStreamSource(0,m_pVB,0,sizeof(SAnimVertex));
	_Render->GetDevice()->SetFVF(SAnimVertex::FVF);
	_Render->GetDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
}